def activate_adjacent_engines(engine_statuses, current_engine, activation_time):
    """激活指定引擎的相邻引擎。计算并更新左右两边的引擎状态。
    - current_engine: 当前引擎的索引。
    - activation_time: 当前引擎的激活时间。
    - total_engines: 引擎总数，用于计算边界条件。"""
    total_engines = len(engine_statuses)
    left_engine = total_engines - 1 if current_engine == 0 else current_engine - 1
    right_engine = 0 if current_engine == total_engines - 1 else current_engine + 1
    if engine_statuses[left_engine] == -1 or engine_statuses[left_engine] > activation_time:
        engine_statuses[left_engine] = activation_time
    if engine_statuses[right_engine] == -1 or engine_statuses[right_engine] > activation_time:
        engine_statuses[right_engine] = activation_time


# 读取引擎总数, 条目数量
number_of_engines, number_of_entries = map(int, input().split())

engine_statuses = [-1] * number_of_engines  # 初始化引擎状态数组，初始值为-1表示未激活
start_time = float('inf')  # 设置最早激活时间为无穷大

for _ in range(number_of_entries):
    # 读取激活时间，引擎坐标
    activation_time, engine_index = map(int, input().split())
    
    engine_statuses[engine_index] = activation_time  # 更新指定引擎的激活时间
    start_time = min(start_time, activation_time)  # 更新最早激活时间


"""更新所有引擎的激活状态，直到所有引擎都被激活。
    进行循环检查，若当前时间点有引擎被激活，则激活其相邻引擎，并递增时间步长。"""
continue_update = True
while continue_update:
    for i, status in enumerate(engine_statuses):
        if status == start_time:        
            activate_adjacent_engines(engine_statuses, i, start_time + 1)
    start_time += 1
    """检查列表中是否有引擎处于未激活状态（即状态为 -1）。
    返回值为布尔类型，True表示存在未激活的引擎，False则表示所有引擎均已激活。"""
    continue_update = -1 in engine_statuses
    
last_activation_time = max(engine_statuses)
count_active_engines = sum(status == last_activation_time for status in engine_statuses)
engines_report = ' '.join(str(i) for i, status in enumerate(engine_statuses) if status == last_activation_time)
print(count_active_engines)  # 打印在最后一个激活时间被激活的引擎数量
print(engines_report.strip())  # 打印这些引擎的索引